#include "Pattern.h"
#include "Expression.h"
#include "Context.h"

namespace PatternRecognition {

void AnythingPattern::set(const AutoPointer<TreeExpression::Expression>& expr, CopyPointer<Context>& context) const {
	context->addDefinition(name, expr);
}

int AnythingPattern::match(const AutoPointer<TreeExpression::Expression>& expr) {
	if (signatureHash->isNull()) {
		signatureHash->set(new std::string(expr->getHash()));//TODO memory
		return ANY;
	}
	else {
		if (*(*signatureHash) == expr->getHash()) return ANY;
		else return 0;
	}
}

void TypePattern::set(const AutoPointer<TreeExpression::Expression>& expr, CopyPointer<Context>& context) const {
	context->addDefinition(name, expr);
}

int TypePattern::match(const AutoPointer<TreeExpression::Expression>& expr) {
	if (expr->getHash() == signatureHash) {
		return TYPE;
	}
	else return 0;
}

}
